#ifndef GW2MAPS_H
#define GW2MAPS_H


#include "stdafx.h"
#include <QtWidgets/QMainWindow>
#include "ui_gw2maps.h"
#include <qsystemtrayicon.h>
#include <qmenu.h>
#include <qmessagebox.h>


typedef class SignalClass *PSIGNAL;
struct threadData{Connection *connection; Position *position; int timeToUpdate; HANDLE mutex; bool run, offline; PSIGNAL sig; char *cId; QSystemTrayIcon *trayIcon;};


class SignalClass : public QObject{
	Q_OBJECT
public:
	SignalClass(){}
	~SignalClass(){}

signals:
	void printStr(char*, bool);
};


class Gw2Maps : public QMainWindow
{
	Q_OBJECT

public:
	Gw2Maps(QWidget *parent = 0);
	~Gw2Maps();
	bool runUpdate(){return this->update;}

	public slots:
		void closeEvent(QCloseEvent*);
		void changeEvent(QEvent*);
		void buttonClicked();
		void appendText(char *a, bool flag){cursor.insertText(a); if(flag)free(a);}
		void setOffline(){_data.offline = ui.offline->isChecked();}
		void showInfo();
		void setTracking(){position->setTracking(ui.tracking->isChecked());}
		void trayIconAction(QSystemTrayIcon::ActivationReason);
		void closeFromTray(){closeEvent(0); exit(0);}
		void confirmUpdate();
		
signals:
		void sendText(const char*);

private:
	Ui::Gw2MapsClass ui;
	HANDLE hThread;
	Connection connection;
	Position *position;
	QTextCursor cursor;
	SignalClass signalToPrint;
	struct threadData _data;
	guildPtr guild;
	char path[MAX_PATH];
	QMenu *trayMenu;
	QAction *trayAction[2];
	QIcon icon[2];
	bool update;
	
	void start();
	void stop();
	void initializeTray();
	void saveData();
};

#endif // GW2MAPS_H
